const fs = require('fs');

// 读取CSS文件
const cssFilePath = 'pages/quickOrder/index.wxss';
const outputFile = 'pages/quickOrder/index-rpx.wxss';

fs.readFile(cssFilePath, 'utf8', (err, data) => {
  if (err) {
    console.error('Error reading file:', err);
    return;
  }

  // 使用正则表达式将px替换为rpx，并按照1:2比例转换
  const convertedCss = data.replace(/(\d+)px/g, (match, p1) => {
    return `${p1 * 2}rpx`;
  });

  // 写入新的CSS文件
  fs.writeFile(outputFile, convertedCss, 'utf8', (err) => {
    if (err) {
      console.error('Error writing file:', err);
      return;
    }
    console.log('Conversion completed successfully.');
  });
});
